package com.tbit.uqbike.client.service.impl;

import com.alibaba.fastjson.JSON;
import com.tbit.uqbike.client.constant.AccountConfigExtConstant;
import com.tbit.uqbike.client.dao.core.AccountConfigExtDao;
import com.tbit.uqbike.client.dao.core.BrandConfigDao;
import com.tbit.uqbike.client.pojo.BrandConfig;
import com.tbit.uqbike.client.pojo.newEntity.AccountConfigExt;
import com.tbit.uqbike.client.service.BrandConfigService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author: chen
 * @Description: 品牌配置
 * @Date: 创建于 10:40 2021/1/6
 */
@Slf4j
@Service
public class BrandConfigServiceImpl implements BrandConfigService {
    @Autowired
    private BrandConfigDao brandConfigDao;
    @Autowired
    private AccountConfigExtDao accountConfigExtDao;

    @Override
    public BrandConfig getByAccountId(Integer accountId) {
        BrandConfig brandConfig = brandConfigDao.getByAccountId(accountId);
        brandConfig.setOnlineServiceURL("");
        //获取在线客服链接，兼容老版本
        AccountConfigExt accountConfigExt = accountConfigExtDao.selectByAccountIdAndKey(accountId, AccountConfigExtConstant.ONLINE_SERVICE_URL_KEY);
        if (Objects.nonNull(accountConfigExt)){
            brandConfig.setOnlineServiceURL(accountConfigExt.getParamValue());
        }
        log.info("getByAccountId=------------------>brandConfig:{}", JSON.toJSONString(brandConfig));
        return brandConfig;
    }
}
